<template>
  <div>
    <div v-if="browser === 'IE'">
      <div v-if="platform === 'Win32'">
        <object
          id="TANGER_OCX"
          :classid="classid"
          :codebase="codebase"
          :width="width"
          :height="height"
        >
          <param name="MakerCaption" :value="MakerCaption" />
          <param name="MakerKey" :value="MakerKey" />
          <param name="ProductCaption" :value="ProductCaption" />
          <param name="ProductKey" :value="ProductKey" />
          <param name="NoExpireKey" :value="NoExpireKey" />
          <param name="IsUseUTF8URL" value="-1" />
          <param name="IsUseUTF8Data" value="-1" />
          <param
            name="Caption"
            value="NTKO OFFICE文档控件示例演示 http://www.ntko.com"
          />
          <SPAN
            style="color:red"
          >不能装载文档控件。请在检查浏览器的选项中检查浏览器的安全设置。</SPAN>
        </object>
      </div>
      <div v-if="platform === 'Win64'">
        <object
          id="TANGER_OCX"
          :classid="classidx64"
          :codebase="codebase64"
          :width="width"
          :height="height"
        >
          <param name="MakerCaption" :value="MakerCaption" />
          <param name="MakerKey" :value="MakerKey" />
          <param name="ProductCaption" :value="ProductCaption" />
          <param name="ProductKey" :value="ProductKey" />
          <param name="NoExpireKey" :value="NoExpireKey" />
          <param name="IsUseUTF8URL" value="-1" />
          <param name="IsUseUTF8Data" value="-1" />
          <param
            name="Caption"
            value="NTKO OFFICE文档控件示例演示 http://www.ntko.com"
          />
          <SPAN
            style="color:red"
          >不能装载文档控件。请在检查浏览器的选项中检查浏览器的安全设置。</SPAN>
        </object>
      </div>
    </div>
    <div v-if="browser == 'firefox'">
      <div v-if="platform === 'Linux x86_64'">
        <object
          id="TANGER_OCX"
          name="TANGER_OCX"
          type="application/ntko-plug"
          :height="height"
          :width="width"
          ForOnDocumentOpened="ntkoondocumentopened"
          ForOnSaveToURL="ntkosavetourl"
          ForOnDocumentClosed="OnDocumentClosed"
          ForOnAfterOpenFromURLCallBack="OnAfterOpenFromURLCallBack"
          ForOnBeginOpenFromURL="OnBeginOpenFromURL"
          ForOnCustomMenuCmd2="OnCustomMenuCmd2"
          ForOnCustomToolBarCommand="OnCustomToolBarCommand"
          ForOnCustomButtonOnMenuCmd="ntkocmd"
          ForOnFileCommand="OnFileCommand"
          ForOnCustomFileMenuCmd="OnCustomFileMenuCmd"
          ForOnScreenModeChanged="OnScreenModeChanged"
          ForOnWordBeforeRightClick="OnWordBeforeRightClick"
          ForOnSheetBeforeDoubleClick="OnSheetBeforeDoubleClick"
        >
          <SPAN
            s-t-y-l-e="color:red"
          >不能装载文档控件。请检查文档控件是否已经正确安装</SPAN>
          请点击<a href="ntkoplugins.crx">安装组件</a>
        </object>
      </div>
      <div v-if="platform !== 'Linux x86_64'">
        <object
          id="TANGER_OCX"
          type="application/ntko-plug"
          :codebase="chfixclassid"
          :width="width"
          :height="height"
          ForOnSaveToURL="ntkosavetourl"
          ForOndocumentopened="ntkoondocumentopened"
          ForOnCustomButtonOnMenuCmd="ntkocmd"
          ForOnpublishAshtmltourl="ntkopublishashtml"
          ForOnpublishAspdftourl="ntkopublishaspdf"
          ForOnSaveAsOtherFormatToUrl="ntkosaveasotherurl"
          :_MakerCaption="MakerCaption"
          :_MakerKey="MakerKey"
          :_ProductCaption="ProductCaption"
          :_ProductKey="ProductKey"
          :_NoExpireKey="NoExpireKey"
          :clsid="chfixclassid"
        >
          <SPAN s-t-y-l-e="color:red">尚未安装NTKO Web FireFox跨浏览器插件</SPAN>
        </object>
      </div>
    </div>
    <div v-if="browser == 'chrome'">
      <div v-if="platform === 'Linux x86_64'">
        <object
          id="TANGER_OCX"
          name="TANGER_OCX"
          type="application/ntko-plug"
          :height="height"
          :width="width"
          ForOnDocumentOpened="ntkoondoucment"
          ForOnSaveToURL="ntkosavetourl"
          ForOnDocumentClosed="OnDocumentClosed"
          ForOnAfterOpenFromURLCallBack="OnAfterOpenFromURLCallBack"
          ForOnBeginOpenFromURL="OnBeginOpenFromURL"
          ForOnCustomMenuCmd2="OnCustomMenuCmd2"
          ForOnCustomToolBarCommand="OnCustomToolBarCommand"
          ForOnCustomButtonOnMenuCmd="ntkocmd"
          ForOnFileCommand="OnFileCommand"
          ForOnCustomFileMenuCmd="OnCustomFileMenuCmd"
          ForOnScreenModeChanged="OnScreenModeChanged"
          ForOnWordBeforeRightClick="OnWordBeforeRightClick"
          ForOnSheetBeforeDoubleClick="OnSheetBeforeDoubleClick"
        >
          <SPAN
            s-t-y-l-e="color:red"
          >不能装载文档控件。请检查文档控件是否已经正确安装</SPAN>
          请点击<a href="ntkoplugins.crx">安装组件</a>
        </object>
      </div>
      <div v-if="platform !== 'Linux x86_64'">
        <object
          id="TANGER_OCX"
          type="application/ntko-plug"
          :codebase="codebase"
          :width="width"
          :height="height"
          ForOnSaveToURL="ntkosavetourl"
          ForOndocumentopened="ntkoondoucment"
          ForOnpublishAshtmltourl="ntkopublishashtml"
          ForOnpublishAspdftourl="ntkopublishaspdf"
          ForOnCustomButtonOnMenuCmd="ntkocmd"
          ForOnSaveAsOtherFormatToUrl="ntkosaveasotherurl"
          :_MakerCaption="MakerCaption"
          :_MakerKey="MakerKey"
          :_ProductCaption="ProductCaption"
          :_ProductKey="ProductKey"
          :_NoExpireKey="NoExpireKey"
          :clsid="chfixclassid"
        >
          <SPAN s-t-y-l-e="color:red">尚未安装NTKO Web Chrome跨浏览器插件</SPAN>
        </object>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Editindexdemo",
  data() {
    return {
      // 64位控件的calssid
      classidx64: "clsid:A64E3073-2016-4baf-A89D-FFE1FAA10EE0",
      // 32位控件的classid
      classid: "clsid:A64E3073-2016-4baf-A89D-FFE1FAA10EC0",
      // 谷歌和火狐的classid
      chfixclassid: "{A64E3073-2016-4baf-A89D-FFE1FAA10EC0}",
      // 32位控件包的路径
      codebase: "officecontrol/OfficeControl.cab#version=6.0.0.6",
      // 64位控件包的路径
      codebase64: "officecontrol/OfficeControlx64.cab#version=6.0.0.6",
      // 设置高度
      height: "800px",
      // 设置宽度
      width: "100%",
      // 买断授权密钥如果不是买断可以不用写
      MakerCaption: "",
      // 买断授权密钥如果不是买断可以不用写
      MakerKey: "",
      // 密钥
      ProductCaption: "",
      // 密钥
      ProductKey: "",
      // 解除时间密钥
      NoExpireKey: "",
      // 获取浏览器类型
      browser: "",
      // 获取操作系统位数
      platform: "",
      NtkoUrlTest: "",
    };
  },
  created() {
    const userAgent = navigator.userAgent;
    let browser;
    // eslint-disable-next-line no-unused-vars
    let version;
    const browserMatch = this.uaMatch(userAgent.toLowerCase());
    if (browserMatch.browser) {
      browser = browserMatch.browser;
      version = browserMatch.version;
    }
    const platform = window.navigator.platform;
    this.platform = platform;
    this.browser = browser;
    this.$emit("winplate", platform);
    console.log("linux:" + this.platform);
  },
  methods: {
    uaMatch(ua) {
      const rMsie = /(msie\s|trident.*rv:)([\w.]+)/;
      const rFirefox = /(firefox)\/([\w.]+)/;
      const rOpera = /(opera).+version\/([\w.]+)/;
      const rChrome = /(chrome)\/([\w.]+)/;
      const rSafari = /version\/([\w.]+).*(safari)/;
      const match = rMsie.exec(ua);
      if (match != null) {
        return { browser: "IE", version: match[2] || "0" };
      }
      const firefoxmatch = rFirefox.exec(ua);
      if (firefoxmatch != null) {
        return {
          browser: firefoxmatch[1] || "",
          version: firefoxmatch[2] || "0",
        };
      }
      const operamatch = rOpera.exec(ua);
      if (operamatch != null) {
        return { browser: operamatch[1] || "", version: operamatch[2] || "0" };
      }
      const chromematch = rChrome.exec(ua);
      if (chromematch != null) {
        return {
          browser: chromematch[1] || "",
          version: chromematch[2] || "0",
        };
      }
      const safarimatch = rSafari.exec(ua);
      if (safarimatch != null) {
        return {
          browser: safarimatch[2] || "",
          version: safarimatch[1] || "0",
        };
      }
      if (match != null) {
        return { browser: "", version: "0" };
      }
      // eslint-disable-next-line no-undef
      return userAgent;
    },

    ntkoSetReturnValueToParentPage(data1, text1) {
      const ntkojb = this.NtkoJudgingBrowsers();
      if (ntkojb) {
        window.opener.ieattachEventntko(data1, text1);
      } else {
        window.external.SetReturnValueToParentPage(data1, text1);
      }
    },
    NtkoJudgingBrowsers() {
      if ("SetReturnValueToParentPage" in window.external) {
        return false;
      } else {
        return true;
      }
    },
    NtkoPerClose() {
      // eslint-disable-next-line no-array-constructor
      const ntkoarry = new Array();
      ntkoarry.push(this.NtkoUrlTest);
      this.ntkoSetReturnValueToParentPage("ntkoSendclose", ntkoarry);
    },
    ntkourltext() {
      this.NtkoUrlTest = window.location.href;
      // eslint-disable-next-line eqeqeq
      if (this.NtkoUrlTest != null && this.NtkoUrlTest != "") {
        // eslint-disable-next-line no-array-constructor
        const ntkoarry = new Array();
        ntkoarry.push(this.NtkoUrlTest);
        this.ntkoSetReturnValueToParentPage(
          "ntkoSendDataToChildtext",
          ntkoarry
        );
      }
    },
  },
};
</script>

<style scoped></style>
